<?php
/**
 * Descript 安全类
 * User: blue
 * Date: 2018/8/5 10:11
 */

namespace app\lib\serverLib;


class Security
{
    /**
     * @param int $len 随机字符长度
     * @param bool $onlyNum 是否为纯数字
     * @return bool|string
     */
    public static function makeRandon($len=32, $onlyNum=false){
        if($onlyNum===false){
            $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        }else if($onlyNum===true){
            $chars='0123456789';
        }else{
            return false;
        }
        $str="";
        $max=strlen($chars)-1;
        for($i=0;$i<$len;$i++){
            $str.=$chars[rand(0,$max)];
        }
        return $str;
    }

}